const http = require("http");

const abc = {};

const app = http.createServer((req, res) => {
    if (req.url === "/login") {
        const user = {
            username: "zhangsan",
            nickname: "张三",
        };

        const key = "12321hpij3o2i1j3oi21j";

        abc[key] = user;

        res.setHeader("Set-Cookie", `sessionId=${key}`);
    }

    if (req.url === "/me") {
        const arr = req.headers.cookie.split("=");
        res.end(JSON.stringify(abc[arr[1]]));
        return;
    }

    res.end("Hello World");
});

// if (req.url === "/cookie") {
//     res.setHeader("Set-Cookie", "sessionId=2193219321j389u2193u1");
//     res.end("cookie 已设置");
//     return;
// }

// if (req.url === "/get/cookie") {
//     res.end(req.headers.cookie);
//     return;
// }

app.listen(3000);
